// 部门接口列表
export default function (router, DBserve) {
  // 新增部门
  router.post("/add/department", (req, res) => {
    // console.log(req.body);
    DBserve({
      DBname: "department",
      order: "count",
      option: { $or: [{ number: req.body.number }, { name: req.body.name }] },
    }).then(data => {
      if (data.data > 0) return res.json({ code: 201, message: "部门编号或部门名称已存在！" });
      DBserve({
        DBname: "department",
        order: "insert",
        option: req.body,
      }).then(data => {
        // console.log(data);
        res.json(data);
      });
    });
  });
  // 查询部门
  router.get("/department", (req, res) => {
    // console.log(req.body);
    DBserve({
      DBname: "department",
      order: "find",
      option: {},
    }).then(data => {
      res.json(data);
    });
  });
  // 删除部门
  router.delete("/department", (req, res) => {
    // console.log(req.body);
    DBserve({
      DBname: "department",
      order: "remove",
      option: { _id: req.body._id },
    }).then(data => {
      res.json(data);
    });
  });
  // 修改部门
  router.post("/update/department", (req, res) => {
    DBserve({
      DBname: "department",
      order: "update",
      option: req.body,
    }).then(data => {
      res.json(data);
    });
  });
}
